package com.all.play.mymvptwo.model;

import android.util.Log;

import com.all.play.mymvptwo.MyCallBack;
import com.all.play.mymvptwo.bean.InfoBean;
import com.google.gson.Gson;
import com.zhy.http.okhttp.OkHttpUtils;

import java.util.List;

import okhttp3.Call;

/**
 * Created by 聪明一只哈 on 2018/5/16.
 * Time: 2018/5/16  11:14
 */

public class IModelImpl implements IModel {

    @Override
    public void loadDatas(final InfoOnLoadListener infoOnLoadListener) {

//        OkHttpUtils
//                .post()
//                .url("http://www.kuaidi100.com/query?type=yuantong&postid=11111111111")
//                .build()
//                .execute(new StringCallback() {
//
//                    @Override
//                    public void inProgress(float progress, long total, int id) {
//
//                        Log.i("ImodelImplgetNet", "onResponse: "+total+"~~~"+progress);
//                        infoOnLoadListener.inprogress(total,progress);
//
//                    }
//
//                    @Override
//                    public void onError(Call call, Exception e, int id) {
//
//                    }
//
//                    @Override
//                    public void onResponse(String response, int id) {
//
//                        Gson gson = new Gson();
//
//                        Log.i("ImodelImplgetNet", "onResponse: "+response);
//
//                        InfoBean infoBean = gson.fromJson(response, InfoBean.class);
//                        if(infoBean!=null){
//                            List<InfoBean.DataBean> data = infoBean.getData();
//
//
//                            infoOnLoadListener.onComplete(data);
//                        }
//
//
//
//                    }
//                });


        OkHttpUtils
                .post()
                .url("http://www.kuaidi100.com/query?type=yuantong&postid=11111111111")
                .build()
                .execute(new MyCallBack(){


                    @Override
                    public void inProgress(float progress, long total, int id) {
                        Log.i("ImodelImplgetNet", "onResponse: "+total+"~~~"+progress);
                        infoOnLoadListener.inprogress(total,progress);
                    }

                    @Override
                    public void onError(Call call, Exception e, int id) {

                    }

                    @Override
                    public void onResponse(String response, int id) {
                        Gson gson = new Gson();

                        Log.i("ImodelImplgetNet", "onResponse: "+response);

                        InfoBean infoBean = gson.fromJson(response, InfoBean.class);
                        if(infoBean!=null){
                            List<InfoBean.DataBean> data = infoBean.getData();


                            infoOnLoadListener.onComplete(data);
                        }
                    }
                });

    }
}
